import {HANDLESETLANG, HANDLESETLANGLIST} from '@/store/actionTypes/lang.js';
import StorageUtils from '@/utils/storageUtils';
const initalState = {
  lang: 'zh',
  langList: [],
};

/***
 *
 * 管理用户的状态
 */
const langReduce = (state = initalState, action) => {
  switch (action.type) {
    case HANDLESETLANG:
      const lang = action.payload || 'zh';
      changLang(lang);
      return {...state, lang};
    case HANDLESETLANGLIST:
      const langList = action.payload || [];
      return {...state, langList};
    default:
      return state;
  }
};

const changLang = async lang => {
  await StorageUtils.setItem('APP_LANG', lang);
};
export default langReduce;
